<template>
  <div class="photo-container">
    <!-- 顶部选项卡 -->
    <div id="slider" class="mui-slider">
      <div
        id="sliderSegmentedControl"
        class="
          mui-scroll-wrapper
          mui-slider-indicator
          mui-segmented-control
          mui-segmented-control-inverted
        "
      >
        <div class="mui-scroll">
          <a
            :class="['mui-control-item', item.en === 'top' ? 'mui-active' : '']"
            v-for="item in cates"
            :key="item.en"
            @tap="getNewsByCate(item.en)"
          >
            {{ item.zh }}
          </a>
        </div>
      </div>
    </div>
    <!-- 底部列表 -->
    <ul class="photo_list">
      <li
        v-for="item in list"
        :key="item.uniquekey"
        @tap="detail(item.uniquekey)"
      >
        <img v-lazy="item.thumbnail_pic_s" v-if="item.thumbnail_pic_s" />
        <div class="info" v-if="item.thumbnail_pic_s">
          <h3>{{ item.title }}</h3>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
import mui from "../../lib/mui/js/mui.min.js";
import cates from "../../cate.config.js";
import { Toast } from "mint-ui";
export default {
  data() {
    return {
      cates,
      list: [
        {
          uniquekey: 1,
          thumbnail_pic_s: "../../static/imgs/muwu.jpg",
          title: "木屋",
        },
      ],
    };
  },
  created() {
    this.getNewsByCate();
  },
  mounted() {
    mui(".mui-scroll-wrapper").scroll().scrollTo(0, 0, 100); //100毫秒滚动到顶
  },
  methods: {
    getNewsByCate(cate = "top") {
      // this.axios
      //   .get(
      //     "news/index?type=" +
      //       cate +
      //       "&key=eac50bc36af78dbe3467c8358f259e59&is_filter=1&page=1&page_size=30"
      //   )
      //   .then((result) => {
      //     if (result.data.error_code === 0) {
      //       this.list = result.data.result.data;
      //     } else {
      //       Toast("聚合数据接口超过每日接入次数");
      //     }
      //   })
      //   .catch((err) => {
      //     Toast(err.message);
      //   });
    },
    detail(uniquekey) {
      this.$router.push({ name: "photoinfo", params: { uniquekey } });
    },
  },
};
</script>

<style lang='less' scoped>
.photo-container {
  padding: 0 8px;
  .mui-scroll {
    a {
      touch-action: none;
    }
  }
  .photo_list {
    list-style: none;
    margin: 0;
    padding: 0;
    li {
      background: #ccc;
      text-align: center;
      margin-bottom: 8px;
      box-shadow: 0 0 0 2px #ccc;
      position: relative;
      img {
        width: 100%;
        vertical-align: middle;
      }
      img[lazy="loading"] {
        width: 40px;
        height: 215px;
        margin: auto;
      }
      .info {
        color: #fff;
        text-align: left;
        position: absolute;
        bottom: 0;
        width: 100%;
        background-color: rgba(0, 0, 0, 0.4);
        h3 {
          font-size: 14px;
          line-height: 30px;
        }
      }
    }
  }
}
</style>